layui.use(['layer', 'jquery', 'laydate', 'util'], function () {
    let layer = layui.layer
        , util = layui.util
        , laydate = layui.laydate
        , $ = layui.jquery;

    $(function () {
        //显示头部学生个人信息
        $.ajax({
            url: "/getInfo",
            type: 'post',
            data: {
                userName: sno,
                role: 1

            },
            dataType: 'json',
            success: function (data) {
                $("#sname").html(data.name);
                $("#sno").html(data.sNO);
                $("#collName").html(data.collName);
                $("#majorName").html(data.majorName);
                $("#classes").html(data.classes);
                //显示头部学生的指导老师
                if (data.tNO !== null || data.tNO !== '') {
                    $.ajax({
                        url: "/getInfo",
                        type: 'post',
                        data: {
                            userName: data.tNO,
                            role: 2
                        },
                        dataType: 'json',
                        success: function (json) {
                            $("#tname").html(json.name);
                        }
                    });
                }
            }
        })

        //显示头部学生课题信息
        $.ajax({
            url: "/getPaper",
            type: 'post',
            data: {
                userName: sno, state: "任务书", type: 1, page: 1, limit: 100
            },
            dataType: 'json',
            success: function (json) {
                if (json.count != 0) {
                    $("#title").html(json.data[0].title);
                    $("#state").html(json.data[0].state);
                } else {
                    $.ajax({
                        url: "/titleInfo",
                        type: 'post',
                        data: {
                            sno: sno, page: 1, limit: 100
                        },
                        dataType: 'json',
                        success: function (data) {
                            for (let i = 0; i < data.count; i++) {
                                if (data.data[i].state === "审核中") {
                                    $("#title").html(data.data[i].title);
                                    $("#state").html(data.data[i].state);
                                }
                            }
                        }
                    })
                }
            }
        })


        //显示我的进度信息
        $.ajax({
            url: "/queryAllStageTime",
            type: 'post',
            data: {},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                for (let i = 0; i < data.count; i++) {
                    $("#start" + (i + 1)).html(data.data[i].startTime);
                    $("#end" + (i + 1)).html(data.data[i].endTime);
                    let endTime = new Date(Date.parse(data.data[i].endTime)) //结束日期
                        , startTime = new Date(Date.parse(data.data[i].startTime))
                        , serverTime = new Date(); //本地时间//本地时间
                    if (serverTime < startTime) {
                        $("#state" + (i + 1)).html("未开始");
                        $("#" + (i + 1)).css("background-color", 'gray');
                    } else if (startTime < serverTime && serverTime < endTime) {
                        $("#state" + (i + 1)).html("进行中");
                        $("#" + (i + 1)).css("background-color", 'orange');
                    } else if (serverTime > endTime) {
                        $("#state" + (i + 1)).html("已结束");
                        $("#" + (i + 1)).css("background-color", '#009f95');
                    }
                    //clearTimeout(thisTimer);
                    util.countdown(endTime, serverTime, function (date, serverTime, timer) {
                        let str = date[0] + '天';
                        $('#days' + (i + 1)).html(str);
                        //thisTimer = timer;
                    });
                }
            }
        })

        //显示学生答辩信息
        $.ajax({
            url: "/getStuDefence",
            type: 'post',
            data: {
                sno: sno
            },
            dataType: 'json',
            success: function (data) {
                if (data !== null) {
                    $("#time").html(data.groupTime);
                    $("#place").html(data.groupAddress);
                    let endTime = new Date(Date.parse(data.groupTime)) //答辩日期
                        , serverTime = new Date(); //本地时间
                    if (serverTime > endTime) {
                        $("#Defense-Group-title").html("答辩已完成");
                        $("#Defense-Group").css("background-color", '#009f95');
                    } else {
                        $("#Defense-Group-title").html("已分配答辩组");
                        $("#Defense-Group").css("background-color", 'orange');
                    }
                    // clearTimeout(thisTimer);
                    util.countdown(endTime, serverTime, function (date, serverTime, timer) {
                        let str = date[0] + '天' + date[1] + '时' + date[2] + '分' + date[3] + '秒';
                        $('#timeout').html(str);
                        // thisTimer = timer;
                    });
                }
            }
        })

    })


});
